// run: $exec < input
#include <iostream>
#include <queue>
#include <cstring>

int const maxn = 200;
int map[maxn][maxn];
bool vis[maxn];
int dist[maxn];
int n;

void init()
{
	for (int i = 0; i < n; i++) {
		dist[i] = 0;
		vis[i] = false;
	}
}


int prim()
{
	int ret = 0; dist[0] = 0; vis[0] = true;
	for (int i = 1; i < n; i++) dist[i] = map[0][i];
	for (int i = 1; i < n; i++) {
		int pos, max = 0;
		for (int j = 1; j < n; j++)
			if (!vis[j] && dist[j] > max) { max = dist[j]; pos = j; }
		ret += dist[pos];
		vis[pos] = true;
		for (int j = 1; j < n; j++)
			if (j != pos && map[pos][j] > dist[j])
				dist[j] = map[pos][j];
	}
	return ret;
}

int main()
{
	std::ios::sync_with_stdio(false);
	while (std::cin >> n) {
		init();
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) std::cin >> map[i][j];
		std::cout << prim() << '\n';
	}
}

